<?php
/**
 * 协程化风格的客户端
 * 并不能实现异步交互
 */
use Swoole\Coroutine\Client;
use function Swoole\Coroutine\run;

$sock_type = SWOOLE_SOCK_TCP;
if (isset($argv[1]) && 'udp' == $argv[1]) $sock_type = SWOOLE_SOCK_UDP;

run(function () use($sock_type) {
    $client = new Client($sock_type);
    if (!$client->connect('127.0.0.1', 9503, 0.5)) {
        echo "connect failed. Error: {$client->errCode}\n";
    }
    $client->send("hello world\n");
    echo $client->recv();
    $client->close();
});
